package com.grandtech.insurance.feign;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Configuration
public class FeignConfig implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        /*方法一：nacos里面增加配置，token参数为空*/
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        /*HttpServletRequest request = attributes.getRequest();
        requestTemplate.header("Authorization", request.getHeader("Authorization"));*/
        /*方法二：设置永久token*/
        //requestTemplate.header("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImNvbnRleHRVc2VySWQiOiIwIiwiY29udGV4dE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJjb250ZXh0RGVwdElkIjoiMCIsImNvbnRleHRBcHBsaWNhdGlvbklkIjoiMCIsImlhdCI6MTYwMDc2MDczNiwiZXhwIjo0NzU0MzYwNzM2fQ.6KleN4NxVHU6pVKhTbDstCzNLL9_kys7RZK827D05EY");
        //ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        /*ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImNvbnRleHRVc2VySWQiOiIwIiwiY29udGV4dE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJjb250ZXh0RGVwdElkIjoiMCIsImNvbnRleHRBcHBsaWNhdGlvbklkIjoiMCIsImlhdCI6MTYwMDc2MDczNiwiZXhwIjo0NzU0MzYwNzM2fQ.6KleN4NxVHU6pVKhTbDstCzNLL9_kys7RZK827D05EY";
        requestTemplate.header("Authorization", request.getHeader(token));*/
    }

}
